package com.iworkh.spring.web.mvc.controller;

import com.iworkh.spring.web.mvc.domain.vo.School;
import com.iworkh.spring.web.mvc.domain.vo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.Locale;

/**
 * JsonController
 *
 * @author: iworkh-沐雨云楼
 * @date: 2020-01-03
 */
@Controller
@RequestMapping(value = "/springmvc")
public class JsonController {

    @Autowired
    private ResourceBundleMessageSource messageSource;

    @ResponseBody
    @RequestMapping(value = "/get")
    public Student getStudent() {
        System.out.println("iworkhh...getStudent");
        School school = School.builder().id("0001").name("iworkh成神学院").star(5).build();
        Student student = Student.builder().id("1").name("沐雨云楼").age(20).birthday(new Date()).school(school).build();

        return student;
    }

    @RequestMapping(value = "/in18jstl")
    public String testIn18Byjstl() {

        return "success";
    }

    @RequestMapping(value = "/in18Attr")
    public String testgetIn18ByAttr(Locale local) {

        String userNameLabel = messageSource.getMessage("userNameLabel", null, local);

        System.out.println("国际化值：" + userNameLabel);

        return "success";
    }
}
